﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CoreHelper.Validation.Validators
{
    [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)]
    public class RequiredValidatorAttribute : BaseValidatorAttribute
    {
        public RequiredValidatorAttribute() : this(ValidationUtils.Messages.Required)
        {
        }
        public RequiredValidatorAttribute(string errorMessage) : base(errorMessage)
        {
            Sort = -1;
        }

        public override bool IsValid(object value)
        {
            if (value == null) return false;
            if (value is string && value.ToString().Trim().Length == 0) return false;
            return true;
        }
    }
}
